﻿using System.Collections.Generic;
using CoreCms.Net.Web.Admin.Infrastructure;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.ComponentModel;
using CoreCms.Net.Model.Echat;
using CoreCms.Net.Model.ViewModels.Echarts;
using CoreCms.Net.Model.ViewModels.UI;
using NPOI.SS.Formula.Atp;

namespace CoreCms.Net.Web.Admin.Controllers.Echarts
{
    /// <summary>
    ///     分销商表
    /// </summary>
    [Description("分销商表")]
    [Route("api/[controller]/[action]")]
    [ApiController]
    [RequiredErrorForAdmin]
    public class EchartsController : ControllerBase
    {
        /// <summary>
        /// 柱状图演示
        /// </summary>
        /// <returns></returns>
        public AdminUiCallBack BarDemo()
        {
            var jm = new AdminUiCallBack();
            var bm = new BarDemoModel();

            bm.title = new BarTitle()
            {
                subtext = "纯属虚构",
                text = "某地区蒸发量和降水量"
            };

            bm.tooltip = new BarTooltip()
            {
                trigger = "axis"
            };

            bm.legend = new BarLegend()
            {
                data = new List<string>() { "蒸发量", "降水量" }
            };
            bm.calculable = true;
            bm.xAxis = new List<XAxisItem>()
            {
                new XAxisItem()
                {
                    type = "category",
                    data = new List<string>() { "1月", "2月", "3月", "4月", "5月", "6月", "7月", "8月", "9月", "10月", "11月", "12月" }
                }
            };

            bm.yAxis = new List<YAxisItem>()
            {
                new YAxisItem()
                {
                    type = "value"
                }
            };

            bm.series = new List<BarSeriesItem>()
            {
                new BarSeriesItem()
                {
                    name = "蒸发量",
                    type = "bar",
                    data = new List<double>() { 2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4, 3.3 },
                    markPoint= new MarkPoint()
                    {
                        data = new ()
                        {
                            new {type = "max",name = "最大值"},
                            new {type = "min",name = "最小值"}
                        }
                    },
                    markLine = new MarkLine()
                    {
                        data = new List<MarkLineDataItem>()
                        {
                            new MarkLineDataItem(){type = "average",name = "平均值"}
                        }
                    }
                },
                new BarSeriesItem()
                {
                    name = "降水量",
                    type = "bar",
                    data = new List<double>() { 2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0, 2.3 },
                    markPoint= new MarkPoint()
                    {
                        data = new List<object>()
                        {
                            new {name = "年最高",value=182.2,xAxis=7,yAxis=183,symbolSize=18},
                            new {name = "年最低",value=2.3,xAxis=11,yAxis=3}
                        }
                    },
                    markLine = new MarkLine()
                    {
                        data = new List<MarkLineDataItem>()
                        {
                            new MarkLineDataItem(){type = "average",name = "平均值"}
                        }
                    }
                }
            };
            jm.code = 0;
            jm.data = new List<BarDemoModel>() { bm };

            return jm;
        }


        public AdminUiCallBack LineDemo()
        {
            var jm = new AdminUiCallBack();
            var lineDemo = new LineDemoModel();

            lineDemo.title = new LineTitle()
            {
                subtext = "纯属虚构",
                text = "未来一周气温变化"
            };

            lineDemo.tooltip = new LineTooltip()
            {
                trigger = "axis"
            };

            lineDemo.legend = new LineLegend()
            {
                data = new List<string>() { "最高气温", "最低气温" }
            };
            lineDemo.calculable = true;
            lineDemo.xAxis = new List<LineXAxisItem>()
            {
                new LineXAxisItem()
                {
                    type = "category",
                    boundaryGap = false,
                    data = new List<string>() { "周一", "周二", "周三", "周四", "周五", "周六", "周日" }
                }
            };

            lineDemo.yAxis = new List<LineYAxisItem>()
            {
                new LineYAxisItem()
                {
                    type = "value",
                    axisLabel = new AxisLabel()
                    {
                        formatter = "{value} °C"
                    }
                }
            };

            lineDemo.series = new List<LineSeriesItem>()
            {
                new LineSeriesItem()
                {
                    name = "最高气温",
                    type = "line",
                    data = new List<int>() { 11, 11, 15, 13, 12, 13, 10 },
                    markPoint= new MarkPoint()
                    {
                        data = new ()
                        {
                            new {type = "max",name = "最大值"},
                            new {type = "min",name = "最小值"}
                        }
                    },
                    markLine = new MarkLine()
                    {
                        data = new List<MarkLineDataItem>()
                        {
                            new MarkLineDataItem(){type = "average",name = "平均值"}
                        }
                    }
                },
                new LineSeriesItem()
                {
                    name = "最低气温",
                    type = "line",
                    data = new List<int>() { 1, -2, 2, 5, 3, 2, 0},
                    markPoint= new MarkPoint()
                    {
                        data = new List<object>()
                        {
                            new {name = "周最低",value=-2,xAxis=1,yAxis=-1.5},
                        }
                    },
                    markLine = new MarkLine()
                    {
                        data = new List<MarkLineDataItem>()
                        {
                            new MarkLineDataItem(){type = "average",name = "平均值"}
                        }
                    }
                }
            };
            jm.code = 0;
            jm.data = new List<LineDemoModel>() { lineDemo };

            return jm;
        }

    }
}
